package com.tianruan.psychological.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.tianruan.psychological.common.constant.GlobalExceptionEnum;
import lombok.Data;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: Dong
 * @Email: dong980514280@gmail.com
 * @Create: 2019-11-19 20:12
 * @PS 返回类
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class VResponse<T> {

    public static final int SUCCESS = 200;

    public static final String STATUS_SUCCESS = "success";
    public static final String STATUS_FAIL = "fail";

    private Integer code = SUCCESS;

    private String status;

    private Integer amount;

    private String msg;

    private T result;




    public VResponse(int errCode, String errMsg, String status) {
        this.code = errCode;
        this.msg = errMsg;
        this.status = status;
    }

    public VResponse(int code, T result, String status) {
        this.code = code;
        this.result = result;
        this.status = status;
    }

    public VResponse(int code, Integer amount, T result, String status) {
        this.code = code;
        this.amount = amount;
        this.result = result;
        this.status = status;
    }

    public VResponse(int code, String msg, T result, String status) {
        this.code = code;
        this.msg = msg;
        this.result = result;
        this.status = status;
    }

    public VResponse(int code, Integer amount, String msg, T result, String status) {
        this.code = code;
        this.amount = amount;
        this.msg = msg;
        this.result = result;
        this.status = status;
    }

    public VResponse() {

    }

    public static <T> VResponse<T> success(T result){
        return new VResponse<T>(SUCCESS, result, STATUS_SUCCESS);
    }

    public static <T> VResponse<T> success(String msg){
        return new VResponse<T>(SUCCESS, msg, STATUS_SUCCESS);
    }


    public static <T> VResponse<T> success(Integer amount, T result){
        VResponse<T> response = new VResponse<T>(SUCCESS, amount, result, STATUS_SUCCESS);
        return response;
    }

    public static <T> VResponse<T> success(String msg,T result){
        VResponse<T> response = new VResponse<T>(SUCCESS, msg, result, STATUS_SUCCESS);
        return response;
    }

    public static <T> VResponse<T> success(Integer amount, String msg,T result){
        VResponse<T> response = new VResponse<T>(SUCCESS, amount, msg, result, STATUS_SUCCESS);
        return response;
    }


    public static <T> VResponse<T> success(GlobalExceptionEnum globalExceptionEnum) {
        VResponse<T> response = new VResponse<T>(globalExceptionEnum.getCode(), globalExceptionEnum.getMessage(), STATUS_SUCCESS);
        return response;
    }

    public static <T> VResponse<T> error(int code,String msg){
        return new VResponse<T>(code, msg, STATUS_FAIL);
    }

    public static <T> VResponse<T> error(GlobalExceptionEnum globalExceptionEnum) {
        VResponse<T> response = new VResponse<T>(globalExceptionEnum.getCode(), globalExceptionEnum.getMessage(), STATUS_FAIL);
        return response;
    }


//
//    public int getCode() {
//        return code;
//    }
//
//    public void setCode(int code) {
//        this.code = code;
//    }
//
//    public Integer getAmount() {
//        return amount;
//    }
//
//    public void setAmount(Integer amount) {
//        this.amount = amount;
//    }
//
//    public String getMsg() {
//        return msg;
//    }
//
//    public void setMsg(String msg) {
//        this.msg = msg;
//    }
//
//    public T getResult() {
//        return success;
//    }
//
//    public void setResult(T success) {
//        this.success = success;
//    }

}
